<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('物品分类信息')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <input type="hidden" id="parentId" name="parentId"><!--ztree数据-->
                <div class="select-list">
                    <ul>
                        <li>
                            关键字：<input type="text" placeholder="关键字" name="keyword"/>
                        </li>
                        <li>

                        </li>
                        <li>
                            上级分类：
                        </li>
                        <li>
                            <div class="form-group">
                                <div class="col-sm-8">
                                    <div class="btn-group">
                                        <button type="button" onclick="read()" class="btn btn-default dropdown-toggle" id="categoryName" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                            请选择：<span class="caret"></span>
                                        </button>
                                        <ul id="treeDemo" class="ztree dropdown-menu"></ul>
                                    </div>
                                </div>
                            </div>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
                <i class="fa fa-plus"></i> 添加分类
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: ztree" /> <!--ztree下拉框树状结构插件-->
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var visitTypedatas = [[${@dict.getType('bus_visit_type')}]];
    var prefix = ctx + "/business/goodsCategory";
    $(function () {
        var options = {
            url: prefix + "/query",
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove",
            modalName: "物品分类",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '序号',
                    sortable: true
                },
                {
                    field: 'goodsCategory.categoryName',
                    title: '上级分类',
                    sortable: true
                },

                {
                    field: 'categoryName',
                    title: '分类',
                    sortable: true
                },
                {
                    field: 'categoryDesc',
                    title: '描述',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        //var editClass = row.status == 0 ?'':'disabled';
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" ' +
                            'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push("<a class='btn btn-danger btn-xs' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa fa-remove'></i>删除</a>");
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    $('input[name=startTime]').datetimepicker({
        format:'yyyy-mm-dd',
        autoclose:true
    });
    $('input[name=endTime]').datetimepicker({
        format:'yyyy-mm-dd',
        autoclose:true
    });

    /*分类下拉框*/
    function read(){
        $.get("/business/goodsCategory/treeData", function (result) {
            // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
            console.log(result.data);
            var setting = {
                callback:{
                    onClick:function (a,b,data) {
                        console.log(data);
                        $('#parentId').val(data.id);
                        $('#categoryName').html(data.categoryName);
                    }
                },
                data: {
                    key:{
                        name:'categoryName'
                    },
                    simpleData: {
                        enable: true,
                        idKey: "id",
                        pIdKey: "parentId",
                        rootPId: null
                    }
                }
            };

            // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
            var zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, result.data);
            zTreeObj.expandAll(true);
        })
    }

    /*重置按钮点击事件*/
    function reset() {
        $('#parentId').val('')
        $.form.reset()
        $('#parentId').form.reset()
    }

</script>
</body>
</html>